<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>文章管理页</title> 
    <link rel="shortcut icon" href="/favicon.ico"> 
    
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
 
    <link href="/public/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/public/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/public/admin/css/animate.css" rel="stylesheet">
    <link href="/public/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/admin/css/ourstyle.css?v=4.0.0" rel="stylesheet">
    <link href="/public/admin/js/plugins/layer/skin/layer.css" rel="stylesheet">
<style>
#tab-1 .form-group{
    display:none;
}
</style>
    <!-- 全局js -->
    <script src="/public/admin/js/jquery.min.js?v=2.1.4"></script> 
    <script src="/public/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <!-- 自定义js -->
    <script src="/public/admin/js/content.js?v=1.0.0"></script>
    <script src="/public/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/admin/plugins/laydate/laydate.js"></script>
    <script src="/public/admin/js/article.js"></script>
    <script src="/public/admin/js/common.js"></script>
    <!-- CKeditor -->
    <script src="/public/admin/plugins/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/public/admin/plugins/ckfinder/ckfinder.js"></script> 
    <!-- iCheck -->
    <script src="/public/admin/js/plugins/iCheck/icheck.min.js"></script>
</head>

<body class="fixed-sidebar full-height-layout gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title" style="display:none">
                    <h5>文章内容</h5>
                </div>
                <div class="ibox-content">
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#tab-1"> 基本信息</a></li>
                    </ul>
                    <br/>
                    <div class="row">
                    <form action="{:url('Article/articleHandle')}" method="post" id="articleFrom" class="form-horizontal">
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane active">
                                <div class="form-group" data-name="kind_id">
                                    <label class="col-sm-2 control-label">所属栏目：</label>
                                    <div class="col-sm-8">
                                        <select class="form-control" name="kind_id">
                                        <?php echo $cat_select ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group" data-name="other">
                                    <label class="col-sm-2 control-label">属性类别：</label>
                                    <div class="col-sm-8">
                                        <div class="col-sm-10">
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_tuijian" value="1" {if $info['is_tuijian'] == 1}checked="checked"{/if}>推荐</label>
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_ganhuo" value="1" {if $info['is_ganhuo'] == 1}checked="checked"{/if}>干货</label>
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_duanzi" value="1" {if $info['is_duanzi'] == 1}checked="checked"{/if}>段子</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" data-name="title">
                                    <label class="col-sm-2 control-label">文章标题：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="title" minlength="2" type="text" value="{$info.title}" required="" aria-required="true">
                                    </div>
                                </div>
                                <div class="form-group" data-name="sub_title">
                                    <label class="col-sm-2 control-label">文章副标题：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="sub_title" minlength="2" type="text" value="{$info.sub_title}">
                                    </div>
                                </div>

                                <div class="form-group" data-name="thumb">
                                    <label class="col-sm-2 control-label">文章图片：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input type="text" class="form-control" name="thumb" id="thumb" value="{$info.thumb}" placeholder="" data-title=""> <span class="input-group-btn"> <button type="button" class="btn btn-primary" onclick="BrowseServer('thumb');">选择图片</button> </span>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="form-group" data-name="is_one">
                                    <label class="col-sm-2 control-label"></label>
                                    <div class="col-sm-8">
                                        <div class="col-sm-10">
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_one" value="1" >自动获取文章内容第一张图片</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" data-name="introduce">
                                    <label class="col-sm-2 control-label">文章简介：</label>
                                    <div class="col-sm-8">
                                        <textarea id="introduce" class="form-control valid" name="introduce" placeholder="">{$info.introduce|raw}</textarea>
                                    </div>
                                </div>
                                <div class="form-group" data-name="content">
                                    <label class="col-sm-2 control-label">文章内容：</label>
                                    <div class="col-sm-8">
                                        <textarea id="content" name="content" rows="2" cols="20">{$info.content|htmlspecialchars_decode}</textarea>
                                    </div>
                                </div>
                                <div class="form-group" data-name="phone_content">
                                    <label class="col-sm-2 control-label">（手机端）文章内容：</label>
                                    <div class="col-sm-8">
                                        <textarea id="phone_content" name="phone_content" rows="2" cols="20">{$info.phone_content}</textarea>
                                    </div>
                                </div>
                                
                                <div class="form-group" data-name="source">
                                    <label class="col-sm-2 control-label">文章来源：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="source" type="text" class="configInput" value="{$info.source}">
                                    </div>
                                </div>
                                <div class="form-group" data-name="author">
                                    <label class="col-sm-2 control-label">文章作者：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="author" type="text" class="configInput" value="{$info.author}">
                                    </div>
                                </div>
                                <div class="form-group" data-name="files">
                                    <label class="col-sm-2 control-label">文章附件：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input type="text" class="form-control" name="files" id="files" value="{$info.files}"> <span class="input-group-btn"> <button type="button" class="btn btn-primary" onclick="BrowseServer('files');">选择文件</button> </span>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="form-group" data-name="mark">
                                    <label class="col-sm-2 control-label">文章标签：</label>
                                    <?php $label = explode(',',$info['mark']);?>
                                    {foreach name="label" item="v"}
                                        <div class="col-sm-2"><input type="text" class="form-control" name="mark[]" value="{$v}"></div>
                                    {/foreach}
                                    <button type="button" class="btn btn-primary" onclick="$(this).before('<div class=col-sm-2><input type=text class=form-control name=mark[]></div>')"><i class="fa fa-plus"></i></button>
                                        <label for="scale"></label>
                                </div>
                                
                                <div class="form-group" data-name="link_url">
                                    <label class="col-sm-2 control-label">来源链接：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="link_url" type="text" class="configInput" value="{$info.link_url}">
                                    </div>
                                </div>
                                <div class="form-group" data-name="pics">
                                    <label class="col-sm-2 control-label">文章多图：</label>
                                    <div class="col-sm-8">
                                        <table class="table table-hover">
                                            <thead>
                                                <tr>
                                                    <th style="width:30%">图片</th>
                                                    <!-- <th>链接地址（必填）</th> -->
                                                    <th style="width:30%">图片标题</th>
                                                    <th style="width:80px;">序号</th>
                                                    <th style="width:80px">操作</th>
                                                </tr>
                                            </thead>
                                            <tbody id="SildeImgs">
                                                <tr>
                                                    <td><div class="input-group"><input type="text" class="form-control upload-path" id="slide_img_0" name="slide_img[]" value="" placeholder="请输入图片地址"><span class="input-group-btn"><button type="button" class="btn btn-primary" onclick="BrowseServer('slide_img_0')"><i class="fa fa-search"></i></button></span></div></td>
                                                    <!-- <td><input type="text" class="form-control" id="slide_link_0" name="slide_link[]" value="" placeholder="请输入链接地址"></td> -->
                                                    <td><input type="text" class="form-control" id="slide_alt_0" name="slide_alt[]" value="" placeholder="请输入图片标题"></td>
                                                    <td><input type="text" class="form-control" id="slide_order_0" name="slide_order[]" value="50" placeholder="请输入序号"></td>
                                                    <td><button type="button" class="btn btn-sm btn-success" onClick="addSlideRow();"><i class="fa fa-plus-square"></i> 添加</button></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="form-group" data-name="keywords">
                                    <label class="col-sm-2 control-label">文章关键字：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="keywords" type="text" class="configInput" value="{$info.keywords}">
                                    </div>
                                </div>
                                <div class="form-group" data-name="description">
                                    <label class="col-sm-2 control-label">文章描述：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="description" type="text" class="configInput" value="{$info.description}">
                                    </div>
                                </div>
                                <div class="form-group" data-name="sort_order">
                                    <label class="col-sm-2 control-label">文章序号：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="sort_order" type="number" class="configInput" value="{$info.sort_order}">
                                    </div>
                                </div>
                                <div class="form-group" data-name="other">
                                    <label class="col-sm-2 control-label">其他属性：</label>
                                    <div class="col-sm-8">
                                        <div class="col-sm-10">
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_home" value="1" {if $info['is_home']==1}checked="checked"{/if}>首页展示</label>
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_hot" value="1" {if $info['is_hot'] == 1}checked="checked"{/if}>热点文章（Hot）</label>
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_tj" value="1" {if $info['is_tj'] == 1}checked="checked"{/if}>推荐文章（新鲜事）</label>
                                            <label class="checkbox-inline i-checks">
                                                <input type="checkbox" name="is_hide" value="1" [if condition="$info['is_hide'] == 1"}checked="checked"{/if}>隐藏文章</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" data-name="add_time">
                                    <label class="col-sm-2 control-label">添加时间：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="add_time" type="text" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" required="" aria-required="true" value="{$date}">
                                    </div>
                                </div>
                                

                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <input type="hidden" name="act" value="{$act}">
                                <input type="hidden" name="article_id" value="{$info.article_id}">
                                <button class="btn btn-primary" onclick="ajax_submit_form('articleFrom','{:url('Article/articleHandle')}')" type="button">保存</button>
                            </div>
                        </div> 
                    </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    <script>   
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        editorReplace('content');
        editorReplace('phone_content');
         CKEDITOR.replace( 'introduce', {
             //编辑器初始化语言
             language : 'zh-cn',
             //编辑器初始化功能定制
             toolbar : [
                 ['Source'],
                 // { name: 'document', items : [ 'DocProps' ] },
                 // { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
                 // '/',
                 { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
                 // { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
                 { name: 'links', items : [ 'Link','Unlink' ] },
                 // { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar' ] },
                 // '/',
                 { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
                 // { name: 'colors', items : [ 'TextColor','BGColor' ] },
                 // { name: 'tools', items : [ 'Maximize', 'ShowBlocks', ] },
             ],
             //是否可以自行拖拽编辑器大小
             resize_enabled : false,
             //编辑器高度
             height : '100px',
             //编辑器宽度
             // width : '1000px',
         });
    });
    </script>
<script>
    $("select[name='kind_id']").change(function(){
        var kind_id = $(this).val();
        $.ajax({
            type:'post',
            url:"{:url('Article/getArticleField')}",
            dataType:'json',
            data:{kind_id,kind_id},
            success:function(res){
                if(res.status==1){
                    var article_field = res.article_field;
                    $("#tab-1 .form-group").each(function(i){
                        var dataName = $(this).attr('data-name');
                        if(dataName!='kind_id'){
                            if(isInArray(dataName,article_field)){
                                $(this).show();
                            }else{
                                $(this).hide();
                            }
                        }else{
                            $(this).show();
                        }
                    })
                }else{
                    layer.msg('请求失败');
                }
            }
        })
    })
    $("select[name='kind_id']").trigger('change');


    var htmlText = '<tr id="slideTR_{0}">';
    htmlText += '<td><div class="input-group"><input type="text" class="form-control upload-path" id="slide_img_{0}" name="slide_img[]" value="" placeholder="请输入图片地址"><span class="input-group-btn"><button type="button" class="btn btn-primary" onclick="BrowseServer(\'slide_img_{0}\')"><i class="fa fa-search"></i></button></span></div></td>';
    // htmlText += '<td><input type="text" class="form-control" id="slide_link_{0}" name="slide_link[]" value="" placeholder="请输入链接地址"></td>';
    htmlText += '<td><input type="text" class="form-control" id="slide_alt_{0}" name="slide_alt[]" value="" placeholder="请输入图片标题"></td>';
    htmlText += '<td><input type="text" class="form-control" id="slide_order_{0}" name="slide_order[]" value="50" placeholder="请输入序号"></td>';
    htmlText += '<td><button type="button" class="btn btn-sm btn-danger" onclick="delmySlideRow({0})"><i class="fa fa-minus-square"></i> 删除</button></td></tr>';
    var items = 1;

    function addSlideRow() {
        var lastitem = items - 1;
        var newHtmlTr = htmlText.replace(/\{0\}/g, items);
        $('#SildeImgs').append(newHtmlTr);
        items += 1;
    }
    function delmySlideRow(id) {
        $("#slideTR_" + id).remove();
    } 

    var jsonstr2 = '<?php echo $info['pics'] ?>';
    // console.log(jsonstr2);
    // $(function () {
        // $('.i-checks').iCheck({
        //     checkboxClass: 'icheckbox_square-green',
        //     radioClass: 'iradio_square-green',
        // });
        // DoPost("addAdsForm");
        FillAds(''+jsonstr2+'');
        //JS加载广告内容
        function FillAds(content) {
            // var json = eval(content);
            // var json = eval("("+content+")");
            var json = JSON.parse(content);
            // alert(content);
            // for(i=0;i<json.length;i++)
            for(var i in json)
            {
                if(i ==0)
                {
                    // $("#slide_width").val(json[0].width);
                    // $("#slide_height").val(json[0].height);
                }
                else
                {
                    addSlideRow();//增加一行
                }
                $("#slide_img_"+i).val(json[i].image);
                $("#slide_alt_"+i).val(json[i].alt);
                $("#slide_order_"+i).val(json[i].order);
                // $("#slide_icon_"+i).val(json[i].icon);
            }
        }
    // })
    
    CKEDITOR.on('instanceReady', function (ev) {
        var editor = ev.editor,
                dataProcessor = editor.dataProcessor,
                htmlFilter = dataProcessor && dataProcessor.htmlFilter;
        dataProcessor.writer.selfClosingEnd = '>';
        // Make output formatting behave similar to FCKeditor
        var dtd = CKEDITOR.dtd;
        for (var e in CKEDITOR.tools.extend({}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent)) {
            dataProcessor.writer.setRules(e,
                    {
                        indent: true,
                        breakBeforeOpen: true,
                        breakAfterOpen: false,
                        breakBeforeClose: !dtd[e]['#'],
                        breakAfterClose: true
                    });
        }
        // Output properties as attributes, not styles.
        htmlFilter.addRules(
                {
                    elements:
                    {
                        $: function (element) {
                            // Output dimensions of images as width and height
                            if (element.name == 'img') {
                                var style = element.attributes.style;
                                // delete element.attributes.style;//删除宽高
                            }

                            if (!element.attributes.style)
                                // delete element.attributes.style;//删除宽高
                            return element;
                        }
                    },
                    attributes:
                    {
                        style: function (value, element) {
                            // Return #RGB for background and border colors
                            //return convertRGBToHex(value);
                        }
                    }
                });
    });
//layer提示信息
    //  $('input').each(function (index, item) {
    //     var _this = this;
    //     $(this).on('focus', function () {
    //         if ($(_this).attr("data-title")) {
    //             var title = $(_this).attr("data-title");
    //             var id = $(_this).attr("id");
    //             layer.tips(title, '#' + id, {
    //                 tips: [1, '#1ab394'],
    //                 time: 20000
    //             });
    //         }
    //     });
    // })
</script>
</body>
</html>
